package com.base.controller;

import com.base.po.coupon_prestore.CouponGoodsPrestore;
import com.base.po.voip_coupon.CouponGoods;
import com.base.service.COUPON.CouponGoodsPrestoreService;
import com.base.service.COUPON.CouponGoodsService;
import com.base.service.LogsService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 修改365优惠券商品信息服务端
 * 
 * @author K
 *
 */
@Controller
@RequestMapping("/admin")
public class update_CouponGoodsPrestore {

	@Autowired
	private LogsService logsService; // log日志
	@Autowired
	private CouponGoodsPrestoreService couponGoodsPrestoreService; // 商品信息

	// 修改商圈信息
	@RequestMapping(value = "/toUpdateCouponGoodsPrestore", method = RequestMethod.POST)
	public @ResponseBody int toUpdateCouponGoodsPrestore(HttpServletRequest request, @RequestBody CouponGoodsPrestore couponGoodsPrestore) throws Exception {
		if (request.getSession().getAttribute("adminUserId") == null) return -1; // 未登录

		try {
			String showContent = couponGoodsPrestore.getShowcontent().replace("\n", "/");
			String[] saveContent = showContent.split("/");
			couponGoodsPrestore.setSavecontent(JSONArray.fromObject(saveContent).toString().replace("\"", "\'"));
		}catch (Exception e){
			couponGoodsPrestore.setSavecontent(null);
		}

		return couponGoodsPrestoreService.updateByPrimaryKeySelective(couponGoodsPrestore); // 修改
	}
}
